/**
 * Created by IntelliJ IDEA.
 * User: Administrator
 * Date: Dec 31, 2009
 * Time: 10:28:34 AM
 * To change this template use File | Settings | File Templates.
 */
import java.util.*;
import org.jdom.Element;

// Referenced classes of package dk.brics.dsd:
//            DeclareRule, RequireRule, IfRule, ReferenceRule,
//            Schema, UniqueRule, PointerRule, InternalSchemaErrorException,
//            Context

abstract class Rule
    implements Comparable
{

    Rule()
    {
    }

    static List parseList(Element element, Schema schema)
    {
        ArrayList arraylist = new ArrayList();
        Iterator iterator = element.getChildren().iterator();
        do
        {
            if(!iterator.hasNext())
                break;
            Element element1 = (Element)iterator.next();
            if(Schema.isDSDElement(element1))
                arraylist.add(parse(element1, schema));
        } while(true);
        return arraylist;
    }

    static Rule parse(Element element, Schema schema)
    {
        String s = element.getName();
        int i = schema.outermost.rulecount++;
        Object obj;
        if(s.equals("declare"))
            obj = new DeclareRule(element, schema);
        else
        if(s.equals("require"))
            obj = new RequireRule(element, schema);
        else
        if(s.equals("if"))
            obj = new IfRule(element, schema);
        else
        if(s.equals("rule"))
            obj = new ReferenceRule(element, schema);
        else
        if(s.equals("dsd"))
            obj = new Schema(element, schema);
        else
        if(s.equals("unique"))
            obj = new UniqueRule(element, schema);
        else
        if(s.equals("pointer"))
            obj = new PointerRule(element, schema);
        else
            throw new InternalSchemaErrorException();
//        obj.number = i;
        return ((Rule) (obj));
    }

    void findApplicableRules(Context context, SortedSet sortedset, Set set)
    {
        sortedset.add(this);
    }

    public int compareTo(Object obj)
    {
        Rule rule = (Rule)obj;
        if(number < rule.number)
            return -1;
        return number <= rule.number ? 0 : 1;
    }

    void checkRequirements(Context context, Set set)
    {
    }

    void findDeclarations(List list)
    {
    }

    void checkUniqueness(Context context, Set set, Map map, Element element)
    {
    }

    void checkPointers(Context context, Map map, Element element)
    {
    }

    boolean skipProcessing(Context context)
    {
        return false;
    }

    int number;
}
